package com.pyg.goods.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import com.pyg.pojo.TbSellerExample;
import com.pyg.pojo.TbSellerExample.Criteria;
import com.pyg.mapper.TbSellerMapper;
import com.pyg.pojo.TbSeller;
import com.pyg.goods.service.TbSellerService;

import com.pyg.utils.PygStringUtils;
import entity.PageResult;

/**	*  @Author zhuliangcai
*  @Email zhuliangcai@itcast.cn
*  @Date 2018-04-03 20:07:45
*/
@Service
public class TbSellerServiceImpl implements TbSellerService {
	@Autowired
	private TbSellerMapper tbSellerMapper;

	@Override
	public List<TbSeller> findAll() {
		return tbSellerMapper.selectByExample(null);
	}

	@Override
	public PageResult findPage(int pageNum, int pageSize) {
		// 开启分页插件功能
		PageHelper.startPage(pageNum, pageSize);

		Page<TbSeller> page = (Page<TbSeller>) tbSellerMapper.selectByExample(null);

		return new PageResult(page.getTotal(), page.getResult());
	}

	/**
	 * 品牌条件分页
	 *
	 * @param TbSeller
	 *            查询条件
	 * @param pageNum
	 *            当前页面
	 * @param pageSize
	 *            每页记录数
	 * @return
	 */
	@Override
	public PageResult findPage(TbSeller tbSeller, int pageNum, int pageSize) {
		// 开启分页插件功能
		PageHelper.startPage(pageNum, pageSize);

		TbSellerExample example = null;
		if (tbSeller != null) {
			example = new TbSellerExample();
			Criteria criteria = example.createCriteria();
			if (PygStringUtils.isNotEmpty(tbSeller.getSellerId())) {
				criteria.andSellerIdLike("%" + tbSeller.getSellerId() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getName())) {
				criteria.andNameLike("%" + tbSeller.getName() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getNickName())) {
				criteria.andNickNameLike("%" + tbSeller.getNickName() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getPassword())) {
				criteria.andPasswordLike("%" + tbSeller.getPassword() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getEmail())) {
				criteria.andEmailLike("%" + tbSeller.getEmail() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getMobile())) {
				criteria.andMobileLike("%" + tbSeller.getMobile() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getTelephone())) {
				criteria.andTelephoneLike("%" + tbSeller.getTelephone() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getStatus())) {
				criteria.andStatusLike("%" + tbSeller.getStatus() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getAddressDetail())) {
				criteria.andAddressDetailLike("%" + tbSeller.getAddressDetail() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getLinkmanName())) {
				criteria.andLinkmanNameLike("%" + tbSeller.getLinkmanName() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getLinkmanQq())) {
				criteria.andLinkmanQqLike("%" + tbSeller.getLinkmanQq() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getLinkmanMobile())) {
				criteria.andLinkmanMobileLike("%" + tbSeller.getLinkmanMobile() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getLinkmanEmail())) {
				criteria.andLinkmanEmailLike("%" + tbSeller.getLinkmanEmail() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getLicenseNumber())) {
				criteria.andLicenseNumberLike("%" + tbSeller.getLicenseNumber() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getTaxNumber())) {
				criteria.andTaxNumberLike("%" + tbSeller.getTaxNumber() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getOrgNumber())) {
				criteria.andOrgNumberLike("%" + tbSeller.getOrgNumber() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getAddress())) {
				criteria.andAddressEqualTo(tbSeller.getAddress() );
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getLogoPic())) {
				criteria.andLogoPicLike("%" + tbSeller.getLogoPic() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getBrief())) {
				criteria.andBriefLike("%" + tbSeller.getBrief() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getCreateTime())) {
				criteria.andCreateTimeEqualTo(tbSeller.getCreateTime() );
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getLegalPerson())) {
				criteria.andLegalPersonLike("%" + tbSeller.getLegalPerson() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getLegalPersonCardId())) {
				criteria.andLegalPersonCardIdLike("%" + tbSeller.getLegalPersonCardId() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getBankUser())) {
				criteria.andBankUserLike("%" + tbSeller.getBankUser() + "%");
			}
			if (PygStringUtils.isNotEmpty(tbSeller.getBankName())) {
				criteria.andBankNameLike("%" + tbSeller.getBankName() + "%");
			}
		}

		Page<TbSeller> page = (Page<TbSeller>) tbSellerMapper.selectByExample(example);

		return new PageResult(page.getTotal(), page.getResult());
	}

	@Override
	public void add(TbSeller tbSeller) {
		tbSellerMapper.insert(tbSeller);
	}

	@Override
	public void del(String[] ids) {
		for (String id : ids) {
			tbSellerMapper.deleteByPrimaryKey(id);
		}
	}

	@Override
	public TbSeller findOne(String id) {
		return tbSellerMapper.selectByPrimaryKey(id);
	}

	@Override
	public void update(TbSeller tbSeller) {
		tbSellerMapper.updateByPrimaryKey(tbSeller);
	}

}
